home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / FORTH / FORTHMAC / OLD / DOCS / !Forthmacs.docs.ascii.armtraps < prev    next >
Encoding:
Text File  |  1996-06-15  |  9.4 KB  |  252 lines

  1.  
  2. Hardware crashes
  3. ****************
  4.  
  5. This chapter describes how RISC OS Forthmacs copes with hardware 
  6. exceptions such as Prefetch Errors, Address Errors, and Divide by 
  7. Zero, and offers suggestions about debugging software which causes 
  8. such problems.  
  9.  
  10. After a hardware exception (or a hardware-like trap) such as an 
  11. Address Error, Prefetch Error, Divide-by-Zero, etc, RISC OS Forthmacs 
  12. will attempt to recover.  The state of the registers and the stacks 
  13. just before the crash is stored in a safe place, where it may be 
  14. examined with SHOWCRASH. 
  15.  
  16. All registers are saved to the REGISTERS buffer.  The BUG vocabulary 
  17. holds tools for handling the registers saved to this area.  There are 
  18. objects called RR0 RR1 RTOP RSP RPC RSR ... that can be inspected and 
  19. changed by the user.  An example: 
  20.  
  21.          h# fffffff @
  22.                   ------ an exception occurs
  23.          showcrash
  24.          rtop .    h# 8000 to rtop
  25.          showcrash  rtop .
  26.          (restart
  27.  
  28. This is used by several debugger tools and can be freely extended by 
  29. user applications.  
  30.  
  31.  
  32. Error handling
  33. ==============
  34.  
  35. The error-handling is rather complex in this implementation, all 
  36. hardware- or hardware related errors are managed within 
  37. RISC OS Forthmacs runtime system, processor-mode problems are hidden 
  38. before you, and you will have to remember one single level of 
  39. ERROR-MANAGING .  
  40.  
  41. All error conditions at last use ERROR-HANDLE later branching to the 
  42. appropriate specialized error-handler.  You may redefine the handler 
  43. according to your needs.  The error handlers: 
  44.  
  45.     : serve-error       \ ( exeption# -- ) standard error handler
  46.         up@ main-task <> if drop -1 then throw ;
  47.     
  48.     defer handle-error      ' serve-error is handle-error
  49.     defer handle-breakpoint ' serve-error is handle-breakpoint
  50.     defer handle-escape     ' serve-error is handle-escape
  51.     defer handle-data       ' serve-error is handle-data
  52.     defer handle-address    ' serve-error is handle-address
  53.     defer handle-prefetch   ' serve-error is handle-prefetch
  54.     defer handle-div0       ' serve-error is handle-div0
  55.  
  56.  
  57. HANDLE-ERROR, all RISC OS error calls go via this handler, use this to 
  58. generate your own error conditions.  WHY will work perfectly with 
  59. this.  
  60.  
  61. HANDLE-BREAKPOINT, a breakpoint instruction OS_BreakPt will go via 
  62. this handler.  
  63.  
  64. HANDLE-ESCAPE, escape conditions use this handler, currently this 
  65. works like a RISC OS Forthmacs "reset" key outside the EXPECT loop.  
  66.  
  67. HANDLE-ADDRESS, tried to access memory above $3ffffff.  
  68.  
  69. HANDLE-DATA/PREFETCH, access to data/instructions was aborted from the 
  70. MMU, there wasn't any memory.  
  71.  
  72. HANDLE-DIV0, tried to divide by zero 
  73.  
  74.  
  75. Debugging Tools Glossary
  76. ========================
  77.  
  78.  
  79. ________________________________________________________________________
  80. (RESTART            ( -- )                   bug            
  81. Restart RISC OS Forthmacs after a hardware crash, the registers must 
  82. have been saved before (this is done by the error-handler), (RESTART 
  83. takes care about the cpu status.  
  84.  
  85. This can be used for developing debuggers, virtual memory managers 
  86. etc.  
  87.  
  88. Implementation Note: For security reasons, (RESTART can't set 
  89. supervisor mode.  This restricts debuggers using this word to user 
  90. mode debugging.  You could easily change this by adding the 
  91. "set-supervisor-mode" swi in the (RESTART code.  
  92.  
  93.  
  94. ________________________________________________________________________
  95. .REGISTERS          ( -- )                                  
  96. dot-registers
  97. Displays the CPU registers values that were saved the last time that a 
  98. breakpoint or exception occurred.  
  99.  
  100. The contents of the PC have been split to the program-counter RPC and 
  101. the status/flag register RSR 
  102.  
  103.  
  104. ________________________________________________________________________
  105. .SR                 ( --  )                                 
  106. Decodes and displays the contents of the ARM Status Register part of 
  107. the PC register that was saved at the last breakpoint or exception.  
  108. The Status Register contains the Condition Codes, the Priority level 
  109. and the interrupt level.  The display looks something like this: 
  110.          nZcvif    user mode
  111. "nZcvif" is the condition codes.  An upper case letter indicates that 
  112. the corresponding bit is on.  In the case the "Z" (zero) bit is on and 
  113. the other bits (Negative, Carry, oVerflow and the mode registers) are 
  114. off.  
  115.  
  116.  
  117. ________________________________________________________________________
  118. .STACK              ( --  )                                 dot-stack
  119. Displays the Data Stack saved at the last breakpoint or exception.  If 
  120. the breakpoint occurred as a result of a RISC OS signal, the system 
  121. may have been executing a system call at the time of the signal.  If 
  122. so, there may be extra stuff on the stack such as C procedure 
  123. activation frames.  
  124.  
  125.  
  126. ________________________________________________________________________
  127. FTRACE              ( -- )                                  
  128. Display the return stack after a crash, if the return stack pointer 
  129. was outside the RISC OS Forthmacs stack, there will only rudimentary 
  130. information be given.  Tries to give not the cfa's but the words real 
  131. names.  
  132.  
  133.  
  134. ________________________________________________________________________
  135. HANDLE-ADDRESS      ( --  )                  Deferred, System  
  136. This handler is used whenever an address exception has happened, 
  137. mostly cause by a wrong address using @ ! etc.  
  138.  
  139. RISC OS Forthmacs has a common error handler for all kinds of errors.  
  140. This handler takes care of cpu state, operating system level etc.  All 
  141. register data can be found in REGISTERS , r0 at the lowest address.  
  142. The stacks are saved at RSSAVE and PSSAVE .  
  143.  
  144. See: SHOWCRASH At it's end it jumps into the error-specific handler, 
  145. by default this is SERVE-ERROR in all cases, but you can install your 
  146. own error handling code instead.  The cpu level debugger uses 
  147. HANDLE-BREAKPOINT, virtual memory could be implemented easily using 
  148. HANDLE-DATA and HANDLE-ADDRESS. 
  149.  
  150. See: SHOWCRASH 
  151.  
  152.  
  153. ________________________________________________________________________
  154. HANDLE-BREAKPOINT   ( --  )                  Deferred, System  
  155. This handler is executed whenever a OS_Breakpt instruction was 
  156. trapped.  Use this for more advanced debugging tools.  
  157.  
  158. See: HANDLE-ADDRESS 
  159.  
  160.  
  161. ________________________________________________________________________
  162. HANDLE-DATA         ( --  )                  Deferred, System  
  163. This handler is used whenever a data abort has happened, mostly cause 
  164. by a wrong address using @ ! etc.  
  165.  
  166. See: HANDLE-ADDRESS 
  167.  
  168.  
  169. ________________________________________________________________________
  170. HANDLE-DIV0         ( --  )                  Deferred, System  
  171. This (emulated) exception is executed when a divide by zero error has 
  172. happened.  
  173.  
  174. See: HANDLE-ADDRESS 
  175.  
  176.  
  177. ________________________________________________________________________
  178. HANDLE-ERROR        ( --  )                  Deferred, System  
  179. This handler is used when errors requested by you take place.  Use 
  180. this for your application specific error handling.  
  181.  
  182. See: HANDLE-ADDRESS 
  183.  
  184.  
  185. ________________________________________________________________________
  186. HANDLE-ESCAPE       ( --  )                  Deferred, System  
  187. This handler is used when an escape condition has happened.  Escape 
  188. conditions can be generated by pressing the Ctrl-Sh-F12 key.  
  189.  
  190.  
  191. See: HANDLE-ADDRESS 
  192.  
  193.  
  194. ________________________________________________________________________
  195. HANDLE-PREFETCH     ( --  )                  Deferred, System  
  196. This handler is used whenever a prefetch abort has happened, usually 
  197. caused by executing code in nirvana.  
  198.  
  199. See: HANDLE-ADDRESS 
  200.  
  201.  
  202. ________________________________________________________________________
  203. REGISTERS           ( -- addr  )             bug            
  204. The address of a buffer holding all register contents after the last 
  205. exception.  
  206.  
  207.  
  208. ________________________________________________________________________
  209. RR0                 ( -- n )                 bug            
  210. n is the value contained in the saved copy of register r0.  RR0 may be 
  211. modified with the TO command.  Other data register names are RR0, RSP 
  212. etc.  
  213.  
  214. See: TO .REGISTERS 
  215.  
  216.  
  217. ________________________________________________________________________
  218. RPC                 ( -- n )                 bug            
  219. n is the value contained in the saved copy of the Program Counter.  
  220. This value is used as the address where the program is restarted for 
  221. the STEP , STEPS , and CONTINUE commands.  RPC may be modified with 
  222. the TO command.  Pipeline effects have been cleared.  
  223.  
  224.  
  225. ________________________________________________________________________
  226. RSP                 ( -- n )                 bug            
  227. n is the value contained in the saved copy of the Stack Pointer.  
  228.  
  229.  
  230. ________________________________________________________________________
  231. RSR                 ( -- n )                 bug            
  232. n is the value contained in the saved copy of the Status Register.  
  233. The Status Register contains the Condition Codes, the Priority level 
  234. and the Interrupt level.  RSR may be modified with the TO command.  
  235.  
  236. See: .SR 
  237.  
  238.  
  239. ________________________________________________________________________
  240. RUP                 ( -- n )                 bug            
  241. n is the value contained in the saved copy of the User-area Pointer.  
  242.  
  243. See: RR0 
  244.  
  245.  
  246. ________________________________________________________________________
  247. SHOWCRASH           ( --  )                                 
  248. Displays all the information saved at the last breakpoint or exception 
  249. including the registers (as in .REGISTERS), the data stack (as in 
  250. .STACK), and the return stack (as in FTRACE). 
  251.  
  252.